﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace YJKRevitKernel.FaceCalculateUtility
{
	public abstract class BaseCalculateManager
	{
		protected List<PlanarFacePacker> LstAllInputFace
		{
			get
			{
				return this.m_lstAllInputFace;
			}
			set
			{
				this.m_lstAllInputFace = value;
			}
		}

		public void Calculate()
		{
			this.m_lstUseFaceHandler = this.m_useFaceGroupHandler.GroupFacePacker(this.LstAllInputFace);
			foreach (FaceLinkeHanlder faceLinkeHanlder in this.m_lstUseFaceHandler)
			{
				faceLinkeHanlder.DoWork();
			}
			bool flag;
			do
			{
				flag = true;
				foreach (FaceLinkeHanlder faceLinkeHanlder2 in this.m_lstUseFaceHandler)
				{
					flag &= faceLinkeHanlder2.IfComplete();
				}
			}
			while (!flag);
			new FaceLinkeHanlder((from n in this.LstAllInputFace
			where n.IfNearBoundary
			select n).ToList<PlanarFacePacker>(), false).DoWork();
			foreach (PlanarFacePacker planarFacePacker in this.LstAllInputFace)
			{
				planarFacePacker.ReMergeShape();
			}
		}

		internal static void ResetNumber(ref uint input)
		{
			if (input == 0u)
			{
				input = 1u;
			}
		}

		protected List<PlanarFacePacker> m_lstAllInputFace;

		protected FaceGroupHandler m_useFaceGroupHandler;

		internal List<FaceLinkeHanlder> m_lstUseFaceHandler;
	}
}
